package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceContract;
import com.ruoyi.service.service.IServiceContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维保合同Controller
 * 
 * @author yepanpan
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/service/contract")
public class ServiceContractController extends BaseController
{
    @Autowired
    private IServiceContractService serviceContractService;

    /**
     * 查询维保合同列表
     */
    @PreAuthorize("@ss.hasPermi('service:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceContract serviceContract)
    {
        startPage();
        List<ServiceContract> list = serviceContractService.selectServiceContractList(serviceContract);
        return getDataTable(list);
    }

    /**
     * 导出维保合同列表
     */
    @PreAuthorize("@ss.hasPermi('service:contract:export')")
    @Log(title = "维保合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceContract serviceContract)
    {
        List<ServiceContract> list = serviceContractService.selectServiceContractList(serviceContract);
        ExcelUtil<ServiceContract> util = new ExcelUtil<ServiceContract>(ServiceContract.class);
        util.exportExcel(response, list, "维保合同数据");
    }


    /**
     * 获取维保合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceContractService.selectServiceContractById(id));
    }

    /**
     * 新增维保合同
     */
    @PreAuthorize("@ss.hasPermi('service:contract:add')")
    @Log(title = "维保合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ServiceContract serviceContract)
    {
                serviceContract.setCreateBy(getUsername());
        return toAjax(serviceContractService.insertServiceContract(serviceContract));
    }

    /**
     * 修改维保合同
     */
    @PreAuthorize("@ss.hasPermi('service:contract:edit')")
    @Log(title = "维保合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ServiceContract serviceContract)
    {
                serviceContract.setUpdateBy(getUsername());
        return toAjax(serviceContractService.updateServiceContract(serviceContract));
    }

    /**
     * 删除维保合同
     */
    @PreAuthorize("@ss.hasPermi('service:contract:remove')")
    @Log(title = "维保合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceContractService.deleteServiceContractByIds(ids));
    }
}
